//
//  GlobalConstants.swift
//  FrameProduct
//
//  Created by delegate on 2024/2/3.
//
import UIKit

/// 与屏幕尺寸相关
public enum ScreenSize {
    public static var width: CGFloat {
        UIScreen.main.bounds.size.width
    }
    public static var height: CGFloat {
        UIScreen.main.bounds.size.height
    }
    public static var maxSize: CGFloat {
        max(width, height)
    }
    public static var minSize: CGFloat {
        min(width, height)
    }
    
    public static var statusBarHeight: CGFloat {
        UIApplication.shared.statusBarFrame.height
    }
    public static let navigationBarContentHeight: CGFloat = 44.0
    public static var navigationBarHeight: CGFloat {
        navigationBarContentHeight + statusBarHeight
    }
    public static let tabBarContentHeight: CGFloat = 49.0
    public static var safeAreaInsets: UIEdgeInsets {
        guard let window = UIApplication.shared.delegate!.window! else {
            return .zero
        }
        if #available(iOS 11.0, *) {
            return window.safeAreaInsets
        } else {
            return .zero
        }
    }
    public static var tabBarHeight: CGFloat {
        tabBarContentHeight + safeAreaInsets.bottom
    }
}

/// 全局常量
public struct GlobalConstants {
    /// app的名称
    public static let appDisplayName = (Bundle.main.infoDictionary?["CFBundleDisplayName"] as? String) ?? ""
    /// app的包名
    public static let appBundleIdentifier = (Bundle.main.infoDictionary?["CFBundleIdentifier"] as? String) ?? ""
    /// app的版本号 2.3.5
    public static let appVersion = (Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String) ?? ""
    /// app版本号 235
    public static let appVersionInteger = appVersion.replacingOccurrences(of: ".", with: "", options: .literal, range: nil)
    /// 是不是iOS10之后的版本
    public let isIOS10Later = (NSFoundationVersionNumber >= NSFoundationVersionNumber10_0)
    /// 是不是iPhoneX系列的设备（带刘海屏）
    public static var isIphoneXSeries: Bool {
        return ScreenSize.safeAreaInsets.bottom != 0
    }
}
